<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<!--edge浏览器H5兼容设置-->
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<!--360浏览器H5兼容设置-->
		<meta name="renderer" content="webkit" />
		<title>上传文件</title>
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<!--导入核心文件-->
		<script src="../bootstrap3/js/holder.js"></script>
		<link href="../bootstrap3/css/bootstrap.css" rel="stylesheet" type="text/css">
		<script src="../bootstrap3/jquery-1.9.1.min.js"></script>
		<script src="../bootstrap3/js/bootstrap.js"></script>
		<script src="../bootstrap3/js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
		<!-- 字体图标 -->
		<link rel="stylesheet" href="../bootstrap3/font-awesome-4.7.0/css/font-awesome.css" />
		<link rel="stylesheet" type="text/css" href="../css/layout.css" />
		<link rel="stylesheet" type="text/css" href="../css/top.css" />
		<link rel="stylesheet" type="text/css" href="../css/footer.css" />
	</head>
	<body>
		<div class="container">
			<div class="col-md-10	">
				<div class="panel panel-default">
					<ul class="nav nav-tabs">
						<li><a href="index.html">首页</a></li>
						<li class="active"><a href="upload.html">上传</a></li>
						<li><a href="password.html">修改密码</a></li>
						<li><a href="login.html">注销登录</a></li>
					</ul>
					<div class="panel-body">
						<form id="form-change-avatar" class="form-horizontal" role="form">
							<div class="form-group">
								<label class="col-md-2 control-label">选择文件:</label>
								<div class="col-md-5">
									<img id="img-avatar" src="../images/index/userEntity.jpg" class="img-responsive" />
								</div>
								<div class="clearfix"></div>
								<div class="col-md-offset-2 col-md-4">
									<input type="file" name="file">
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-offset-2 col-sm-10">
									<input id="btn-change-avatar" type="button" class="btn btn-primary" value="上传" />
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
		<script type="text/javascript">
			$("#btn-change-avatar").click(function() {
				$.ajax({
					url: "/fileList/fileUpload?parId=00&parUrl=/home",
					type: "POST",
					data: new FormData($("#form-change-avatar")[0]),
					dataType: "JSON",
					processData: false, // 关闭processData处理数据
					contentType: false, // 关闭contentType发送数据的格式
					success: function(json) {
						if (json.state == 200) {
							location.href = "index.html"
						} else {
							alert("修改失败！" + json.message);
						}
					},
					error: function(xhr) {
						alert("修改头像返回异常" + xhr.status);
					}
				});
			});
		</script>
	</body>

</html>